﻿// =================================================================== 
// 模块说明
//====================================================================
// 创建时间：2018-06-08 16:43:31
// 负责人：Sushee
// ===================================================================
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq.Expressions;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using OF.Utility;
using OF.Component.Model;
using OF.Component.IDAL;
using System.Text;
using OF.Component.DTO;

namespace OF.Component.DAL
{
	
	/// <summary>
	///店铺信息 数据访问层
	/// </summary>	
	internal partial class Shop
	{		
    
        /// <summary>
    	/// 根据断言条件获取单个店铺信息
    	/// </summary>
        public ShopInfo QuerySingle(Expression<Func<ShopInfo, bool>> predicate)
	    {
            return SQLServerProvider.CreateObject(ConnectionStringKey, predicate);
        }
        /// <summary>
    	/// 根据断言条件获获取店铺信息列表
    	/// </summary>
	    public IList<ShopInfo> QueryList(Expression<Func<ShopInfo, bool>> predicate)
	    {
	        return SQLServerProvider.CreateList(ConnectionStringKey, predicate);
	    }

        /// <summary>
        /// 查询列表
        /// </summary>
        /// <param name="scObj"></param>
        /// <returns></returns>
        public IList<ShopDto> SearchList(scShop scObj)
        {
            Database db = DatabaseFactory.CreateDatabase(this.ConnectionStringKey);
            DbCommand dbc = db.GetStoredProcCommand("up_Shop_search");

            db.AddInParameter(dbc, "@Mobile", DbType.String, scObj.Mobile);
            db.AddInParameter(dbc, "@ProvinceId", DbType.Int32, scObj.ProvinceId);
            db.AddInParameter(dbc, "@LocationId", DbType.Int32, scObj.LocationId);
            db.AddInParameter(dbc, "@CreateStartDate", DbType.String, scObj.CreateStartDate);
            db.AddInParameter(dbc, "@CreateEndDate", DbType.String, scObj.CreateEndDate);

            db.AddInParameter(dbc, "@PageIndex", DbType.Int32, scObj.PageIndex);
            db.AddInParameter(dbc, "@PageSize", DbType.Int32, scObj.PageSize);
            db.AddOutParameter(dbc, "@OutCount", DbType.Int32, 4);

            DataSet dr = db.ExecuteDataSet(dbc);
            scObj.TotalRecord = (int)db.GetParameterValue(dbc, "@OutCount");

            return SQLServerProvider.CreateList<ShopDto>(dr.Tables[0]);
        }
    }
	
}